//
//  Interface.swift
//  IteratorPattern
//
//  Created by mac on 2017/11/14.
//  Copyright © 2017年 RRC. All rights reserved.
//

import Foundation

//项止信息接口
protocol IProject {
    //从老板这里看到的就是项目信息
    func getProjectInfo() -> String
    //增加项目
    func add(name:String, num:Int, cost:Int)
    //获得一个可以被遍历的对象
    func iterator() -> ProjectIterator
}

//项目迭代器的接口
protocol IProjectIterator:IteratorProtocol {
    
}

public class ProjectIterator:IProjectIterator{
    //所有的项目都放在ArrayList中
    private var projectList = [IProject]()
    private var currentItem = 0
    //构造函数传入projectList
    init(projectList:Array<IProject>) {
        self.projectList = projectList
    }
    
    //取得下一个值
    public func next() -> Any? {
        if self.currentItem < self.projectList.count {
            let num = self.projectList[self.currentItem]
            self.currentItem += 1
            return num
        }else{
            return nil
        }
    }
    
    public typealias Element = Any
    
    
}
